package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.SysPtReportVo;
import com.ruoyi.system.bo.SysPtReportQueryBo;
import com.ruoyi.system.bo.SysPtReportAddBo;
import com.ruoyi.system.bo.SysPtReportEditBo;
import com.ruoyi.system.service.ISysPtReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 实验报告管理Controller
 *
 * @author 莫修
 * @date 2021-11-28
 */
@Api(value = "实验报告管理控制器", tags = {"实验报告管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/SysReport")
public class SysPtReportController extends BaseController {

    private final ISysPtReportService iSysPtReportService;

    /**
     * 查询实验报告管理列表
     */
    @ApiOperation("查询实验报告管理列表")
    @PreAuthorize("@ss.hasPermi('system:SysReport:list')")
    @GetMapping("/list")
    public TableDataInfo<SysPtReportVo> list(@Validated SysPtReportQueryBo bo) {
        return iSysPtReportService.queryPageList(bo);
    }

    /**
     * 导出实验报告管理列表
     */
    @ApiOperation("导出实验报告管理列表")
    @PreAuthorize("@ss.hasPermi('system:SysReport:export')")
    @Log(title = "实验报告管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<SysPtReportVo> export(@Validated SysPtReportQueryBo bo) {
        List<SysPtReportVo> list = iSysPtReportService.queryList(bo);
        ExcelUtil<SysPtReportVo> util = new ExcelUtil<SysPtReportVo>(SysPtReportVo.class);
        return util.exportExcel(list, "实验报告管理");
    }

    /**
     * 获取实验报告管理详细信息
     */
    @ApiOperation("获取实验报告管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:SysReport:query')")
    @GetMapping("/{reportId}")
    public AjaxResult<SysPtReportVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("reportId") Long reportId) {
        return AjaxResult.success(iSysPtReportService.queryById(reportId));
    }

    /**
     * 新增实验报告管理
     */
    @ApiOperation("新增实验报告管理")
    @PreAuthorize("@ss.hasPermi('system:SysReport:add')")
    @Log(title = "实验报告管理", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody SysPtReportAddBo bo) {
        return toAjax(iSysPtReportService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改实验报告管理
     */
    @ApiOperation("修改实验报告管理")
    @PreAuthorize("@ss.hasPermi('system:SysReport:edit')")
    @Log(title = "实验报告管理", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody SysPtReportEditBo bo) {
        return toAjax(iSysPtReportService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除实验报告管理
     */
    @ApiOperation("删除实验报告管理")
    @PreAuthorize("@ss.hasPermi('system:SysReport:remove')")
    @Log(title = "实验报告管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{reportIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] reportIds) {
        return toAjax(iSysPtReportService.deleteWithValidByIds(Arrays.asList(reportIds), true) ? 1 : 0);
    }
}
